﻿

$(document).ready(function () {
    var name = getUrlArgStr("name");
    var type = getUrlArgStr("nick");
    name = decodeURI(name);
    type = decodeURI(type);
    var typename = "";
    switch (Trim(type)) {
        case "姓名": typename = "truename";
            break;
        case "微信号": typename = "wx_name";
            break;
        case "分享微信号": typename = "wx_name";
            break;
        case "手机号码": typename = "mobile";
            break;
        case "微信好友数量": typename = "wx_number";
            break;
    }

    $(".topcententxt").html(type.replace(/(^\s*)|(\s*$)/g, ""));
    $(".nicknametext").attr("placeholder", type.replace(/(^\s*)|(\s*$)/g, ""));
    $(".nicknametext").val(name.replace(/(^\s*)|(\s*$)/g, ""));
    $("title").html("微街秀 > " + type.replace(/(^\s*)|(\s*$)/g, ""));

    $(".nicksave").click(function () {
        if (!islogin()) { window.location.href = 'login.html'; return; }

        var inputVal = $(".nicknametext").val();
        if (inputVal == "") {
            Alert("请输入" + type);
            return;
        }

        else if (typename == "mobile") {
            if (!checkMobile(inputVal)) {
                Alert("手机格式不正确");
                $(".nicknametext").focus();
                return;
            }
        } else if (typename == "wx_number") {

            //当填写微信好友数量时
            try {
                var num = parseInt($.trim(inputVal));
                if (num >= 100) {
                }
                else {
                    Alert("好友数量至少大于等于100");
                    return;
                }
            }
            catch (err) {
                Alert("输入格式不正确");
                return;
            }

        }
        var area1 = getStorage("area1");
        var area2 = getStorage("area2");
        var area3 = getStorage("area3");

        if (area1 == null) {
            area1 = "";
        }
        if (area2 == null) {
            area2 = "";
        }
        if (area3 == null) {
            area3 = "";
        }

        AjaxStart("ajax/fc_setting.ashx?setting", "&" + typename + "=" + inputVal + "&area1=" + area1 + "&area2=" + area2 + "&area3=" + area3, function (data) {
            if (data.code == "0")
                window.location.href = "Makesh_4.html";
            else
                Alert(data.msg);
        });
    });

    $(".nickicon").click(function () {
        $("#nicknametext").val("");
        $("#nicknametext").focus();
    });
});

function Trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
/* 
* 功能：判断用户输入的手机号格式是否正确 
* 传参：无 
* 返回值：true or false 
*/
function checkMobile(s) {
    var regu = /^1\d{10}$/;
    var molie = /^0\d{2,3}-?\d{7,8}$/;
    var reg400 = /^400-([0-9]){1}([0-9-]{7})$/;

    var moliereg = new RegExp(molie);
    var re400 = new RegExp(reg400);
    var re = new RegExp(regu);

    if (re400.test(s) || moliereg.test(s) || re.test(s)) {
        return true;
    } else {
        return false;
    }
} 

